#!/bin/sh 
# Installation script for Sun Catalyst CDs
#
# Copyright 1997, SunSoft, Inc.
#
# Author: marc.sacoolas@sun.com 
# Date: October 10, 1997
# Last Modified 12-5-97

# initialize variables
DISC_NAME=Sun_Solutions_CD-February_99
ISSUE_NAME="Sun Solutions CD"
ISSUE_DATE="Volume 4 2000"
PORT_NUMBER=7999

export ISSUE_NAME ISSUE_DATE PORT_NUMBER

dir_exist=0
echo ""
echo "          $ISSUE_NAME $ISSUE_DATE initializing ..."
echo ""
	        			


# set CDMOUNT to path from the command line arguements
CDMOUNT=`expr \
        $0'/' : '\(/\)[^/]*//*$' \
        \| $0'/' : '\(.*[^/]\)//*[^/][^/]*//*$' \
        \| .`

# if command line path is current directory then set CDMOUNT to pwd
# CDMOUNT cannot be set to . because other programs/scripts
# need the absolute path in CD_MOUNT
if [ "$CDMOUNT" = "." ]; then
        CDMOUNT=`pwd`
fi
CD_MOUNT=$CDMOUNT
export CD_MOUNT DISC_DIR

#
# os type and arch
#
check_os()
######################################################################
{
        os_ver="`/bin/uname -r | /bin/grep 5\[.]`"

        export os_ver

        if [ -n "$os_ver" ]; then
# must be running Solaris 2.x
                machine_type="`/bin/uname -m`"
                os_type="`/bin/uname -r`"
                if [ "$machine_type" = "i86pc" ]; then
                        OS_TYPE=""
                        CDWARE_ENV=Solaris_x86
                else
# must be on a SPARCarchitecture-based machine
                        bcp="`/bin/pkginfo | /bin/grep SUNWbcp`"
# check for bcp and set CDWARE_ENV accordingly???
                        CDWARE_ENV=Solaris_2
                fi
        else
# must be running Solaris 1.x
                GUI=products/bin/Solaris_1/cdmanager
                GUI_BIN=cdmgr
                CDWARE_ENV=Solaris_1
		test_sunos="`/bin/uname -r | /bin/grep 4.1.4`"
		if [ -n "$test_sunos" ]; then
			SUNOS_VER=4.1.4
		else
			SUNOS_VER=""
		fi

        fi

}

check_os
DISC_DIR="$CDMOUNT/products/bin/httpd/$CDWARE_ENV"
export LD_LIBRARY_PATH CLASSPATH PATH JAVA_HOME DISC_DIR

LD_LIBRARY_PATH=$CD_MOUNT/products/bin/gui/$CDWARE_ENV/lib:/usr/openwin/lib:/usr/lib:$LD_LIBRARY_PATH
CLASSPATH=.:$CD_MOUNT/products/NetResultsCD:$CD_MOUNT/products/bin/gui/CDlaunch:$CD_MOUNT/products/bin/java/$CDWARE_ENV/lib/rt.jar:$CLASSPATH



JAVA_HOME=$CD_MOUNT/products/bin/java/$CDWARE_ENV

if [ "$OPENWINHOME" = "" ]; then
	OPENWINHOME="/usr/openwin"; export OPENWINHOME	
fi
if [ "$HOME" = "" ]; then
	
        HOME="/"; export HOME
fi

# set the dir where all the companies live
PRODUCT_DIR=$CD_MOUNT/products
export PRODUCT_DIR 

# get nodename
NODENAME=`/bin/hostname`

if [ "$NODENAME" = "" ];then 
	NODENAME = "localhost"
fi
export NODENAME

# legal, readme, etc.
        #if [ "$CDWARE_ENV" != "Solaris_1" -a "$MARC" = "" ]; then
                #use starting java app
                #$CD_MOUNT/products/bin/java/$CDWARE_ENV/bin/jre CDaudio $CD_MOUNT/products/bin/gui/CDlaunch& 
        #        $CD_MOUNT/products/bin/java/$CDWARE_ENV/bin/jre CDlaunch $CD_MOUNT/products/bin/gui/CDlaunch $DISC_DIR                                    
        #else
               # cat $CD_MOUNT/products/bin/gui/CDlaunch/license.txt
        #fi

# exit if user has requested from CDlaunch; do clean-up
#if [ -f $DISC_DIR/nostart ];then
#	# kill sound
#	if [ -r $DISC_DIR/sound.pid ]; then
#        kill -9 `cat $DISC_DIR/sound.pid`
#	fi
#	rm -r $DISC_DIR
#	exit 0
#fi

        if [ "$CDWARE_ENV" != "Solaris_x86" ]; then
	CLASSPATH=$CD_MOUNT/products/bin/gui/$CDWARE_ENV/java_301:$CLASSPATH
	else
        CLASSPATH=$CD_MOUNT/products/bin/gui/$CDWARE_ENV/java_30:$CLASSPATH
	fi


#if [ ! -h $DISC_DIR/products ]; then
#        ln -s $PRODUCT_DIR $DISC_DIR
#fi
#
#if [ ! -h $DISC_DIR/.cgi-bin ]; then
#        ln -s $PRODUCT_DIR/.bin/httpd/$CDWARE_ENV $DISC_DIR/.cgi-bin
#fi
#
#if [ ! -h $DISC_DIR/home ]; then
#        ln -s $HOME $DISC_DIR/home
#fi


# get around read-only netresults problem
 


if [ "$CDWARE_ENV" = "Solaris_1" ]; then
	export XNLSPATH XKEYSYMDB
	PATH=$DISC_DIR:/usr/ucb:$OPENWINHOME/bin:/usr/bin:/usr/sbin:$PATH
	XNLSPATH=$CD_MOUNT/products/bin/gui/$CDWARE_ENV/nls
	XKEYSYMDB=$CD_MOUNT/products/bin/gui/$CDWARE_ENV/XKeysymDB
else
	OS_REV=`/bin/uname -r | $DISC_DIR/perl -n -e 's?^[0-9]\.([0-9]).*?\1? ? print : print "none";'`
	PATH=$DISC_DIR:/usr/bin:$OPENWINHOME/bin:/usr/sbin:$PATH
fi
	export OS_REV

#	WWW_FIRST=http://$NODENAME:$PORT_NUMBER/index.html
#	WWW_HOME=http://$NODENAME:$PORT_NUMBER/index.html
	WWW_HOME=file://$CD_MOUNT/products/index.html
	WWW_FIRST=file://$CD_MOUNT/products/index.html
	WWW_FIRST=file://$CD_MOUNT/products/proxywarning.html
	# so says Scott

export WWW_HOME WWW_FIRST CDWARE_ENV

	echo ""
	echo "Launching Search Server..."
	echo " "
	#CWD=`pwd`
	cd $CD_MOUNT/products/bin/gui/code
        #$CD_MOUNT/products/bin/java2/$CDWARE_ENV/bin/java SCDServer -u 7999 $CD_MOUNT &
        $CD_MOUNT/products/bin/java2/$CDWARE_ENV/bin/java SCDServer -u 7999 $CD_MOUNT/products &
	server_process=$!
	export server_process

#SunOS search provision TOAST
#echo $server_process
#exit 0
#if [ "$CDWARE_ENV" = "Solaris_1" ]; then
#        ln -s /tmp/solcd/products/catalog/list.wais.html /tmp/solcd/list.link
#        echo "No Search supported on SunOS"
#else
#        ln -s $PRODUCT_DIR/catalog/list.excite.html /tmp/solcd/list.link
#fi
#

search_netscape()
######################################################################
{
if [ "$NETSCAPE_CATALYST" = "" ]; then
#	PATH=$PATH:$CD_MOUNT/products/bin/gui/$CDWARE_ENV
	NETSCAPE_VERSION="`netscape -version 2>&1| $DISC_DIR/perl -n -e 's?\D*([0-9.]*).*?\1? ? print : print "none"'`"
#echo "NETSCAPE_VERSION=$NETSCAPE_VERSION"
#	
	POST_VERSION_4=`echo $NETSCAPE_VERSION|$DISC_DIR/perl -n -e '/[4-9]\./ ? print "good" : print "bad"'`
#echo "POST_VERSION_4=$POST_VERSION_4"
#	#POST_VERSION_301=`echo $NETSCAPE_VERSION|$DISC_DIR/perl -n -e '/3\.(\d[1-9]|[2-9]\d)/ || /[4-9]\./ ? print "old" : print "good"'`
	if [ $POST_VERSION_4 = "good" ];then
		echo
		echo "Netscape Navigator "$NETSCAPE_VERSION" will be used for the Sun Solutions CD"
		echo ""
#		#echo $PATH
		NETSCAPE_CATALYST=`echo $PATH|$DISC_DIR/perl -n -e '
			@DIRS=split(/:/);
			foreach $dir (@DIRS) {
				$dir =~ s/\n//;
				if (-x "$dir/netscape" && -f _) {
					print "$dir/netscape\n";
					last;
				}
			}'`
		export NETSCAPE_CATALYST
	fi
fi
}

search_ie()
######################################################################
{
if [ "$IE_CATALYST" = "" ]; then
#	PATH=$PATH:$CD_MOUNT/products/bin/gui/$CDWARE_ENV
	IE_VERSION="`iexplorer -version 2>&-| $DISC_DIR/perl -n -e 's?\D*([0-9.]*).*?\1? ? print : print "none"'`"
#echo "IE_VERSION=$IE_VERSION"
#	
	POST_VERSION_4=`echo $IE_VERSION|$DISC_DIR/perl -n -e '/[4-9]\./ ? print "good" : print "bad"'`
#echo "POST_VERSION_4=$POST_VERSION_4"
#	#POST_VERSION_301=`echo $IE_VERSION|$DISC_DIR/perl -n -e '/3\.(\d[1-9]|[2-9]\d)/ || /[4-9]\./ ? print "old" : print "good"'`
	if [ $POST_VERSION_4 = "good" ];then
		echo
		echo "Internet Explorer "$IE_VERSION" will be used for the Sun Solutions CD"
		echo ""
#		#echo $PATH
		IE_CATALYST=`echo $PATH|$DISC_DIR/perl -n -e '
			@DIRS=split(/:/);
			foreach $dir (@DIRS) {
				$dir =~ s/\n//;
				if (-x "$dir/iexplorer" && -f _) {
					print "$dir/iexplorer\n";
					last;
				}
			}'`
		export IE_CATALYST
		#echo "loop, IE_CATALYST=$IE_CATALYST"
	fi
fi
}

search_netscape
if [ "$NETSCAPE_CATALYST" = "" ]; then
	search_ie
fi

#echo "Please wait, $ISSUE_NAME $ISSUE_DATE is starting ..."
#echo ""

if [ "$NETSCAPE_CATALYST" = "" -a "$IE_CATALYST" = "" ]; then
	echo
	echo
	echo "Please enter the path to the DIRECTORY of either the Netscape or Internet Explorer version 4 or later executable:"
	read user_path
#echo "user_path=$user_path"
	PATH=$PATH:$user_path

	search_netscape
	if [ "$NETSCAPE_CATALYST" = "" ]; then
		search_ie
	fi
fi
#export CDWARE_ENV

$CD_MOUNT/products/bin/finish.sh &
sleep 40
exit 0
